package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.auth.SaAdminCheckPermission;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.DeleteBookOperateDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocBookDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.VocBookCommand;
import com.cskaoyan.wordmemorize.request.VocBookPageRequest;
import com.cskaoyan.wordmemorize.service.VocBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/voc")
public class AdminVocBookController {

    @Autowired
    VocBookService vocBookService;

    // 添加单词书籍(后端-物料管理-书籍管理)
    @SaAdminCheckPermission("admin:book:add")
    @PostMapping("book")
    public Result addVocBook(@RequestBody VocBookCommand command) {
        vocBookService.addVocBook(command);
        return Result.ok();
    }

    // 更新单词书籍(后端-物料管理-书籍管理)
    @SaAdminCheckPermission("admin:book:update")
    @PutMapping("book")
    public Result updateVocBook(@RequestBody VocBookCommand command){
        vocBookService.updateVocBook(command);
        return Result.ok();
    }

    // 分页展示单词书籍(后端-物料管理-书籍管理)
    @SaAdminCheckPermission("admin:book:search")
    @GetMapping("book/list")
    public Result<PageDTO<VocBookDTO>> getBookPage(VocBookPageRequest pageQuery){
        PageDTO<VocBookDTO> bookPage = vocBookService.getBookPage(pageQuery);
        return Result.ok(bookPage);
    }

    // 删除单词书籍(后端-物料管理-书籍管理)
    @SaAdminCheckPermission("admin:book:delete")
    @DeleteMapping("book/{bookId}")
    public Result<DeleteBookOperateDTO> deleteVocBook(@PathVariable("bookId") Long bookId){
        DeleteBookOperateDTO deleteBookOperateDTO = vocBookService.deleteVocBook(bookId);
        return Result.ok(deleteBookOperateDTO);
    }

    // 批量删除选中的单词书籍(后端-物料管理-书籍管理)
    @SaAdminCheckPermission("admin:book:batchdelete")
    @DeleteMapping("books")
    public Result<List<DeleteBookOperateDTO>> deleteVocBooks(@RequestBody BatchDeleteCommand command){
        List<DeleteBookOperateDTO> deleteBookOperateDTOS = vocBookService.deleteVocBooks(command);
        return Result.ok(deleteBookOperateDTOS);
    }
}
